//
//  HistoryViewController.swift
//  TestProject
//
//  Created by 万想想 on 2020/8/19.
//  Copyright © 2020 edaili. All rights reserved.
//


import Foundation
import Moya
import Alamofire

let RESPONSE_CODE = "code"     //状态码
let RESPONSE_MESSAGE = "msg"  //返回信息描述
let RESPONSE_RESULT = "result" //具体数据
// MARK: -- 返回状态码设置
struct ResponseCode {
    static let success = ""
}
// MARK: -- 请求头设置
struct Header {
    static func toDictionary() -> Dictionary<String, String> {
        return ["Content-Type":"application/json"]
    }
}
// MARK: -- 接口定义
enum API {
    // MARK: --
    case getEndpoint
    
}

// TargetType是moya里面的协议
extension API: TargetType {
    var baseURL: URL {
        return URL.init(string: "https://api.github.com/")!
    }
    var path: String {
        switch self {
        case .getEndpoint:
            return "https://api.github.com/"
        }
        
    }
    
    var method: Moya.Method {
        switch self {
        case .getEndpoint:
            return .get
            
        }
    }
    
    var sampleData: Data {
        return "".data(using: String.Encoding.utf8)!
    }
    // 这个就是API里面的核心。类似理解为AFN里的URLRequest
    var task: Task {
        switch self {
        case .getEndpoint:
             return .requestPlain
        }
    }
    
    var headers: [String : String]? {
        return Header.toDictionary()
    }
}
